import sqlite3

def check_property_user_table():
    # 连接到数据库
    db_path = r'd:\manage1\graduation-project\manage1\manage1\manage\db.sqlite3'
    conn = sqlite3.connect(db_path)
    conn.row_factory = sqlite3.Row  # 允许使用字典方式访问结果
    cursor = conn.cursor()
    
    print("检查property_user表结构:")
    # 获取表结构
    cursor.execute("PRAGMA table_info(property_user)")
    columns = cursor.fetchall()
    
    print("\n表字段信息:")
    for column in columns:
        print(f"ID: {column[0]}, 字段名: {column[1]}, 类型: {column[2]}, 非空: {column[3]}, 默认值: {column[4]}, 主键: {column[5]}")
    
    # 获取表中的数据示例
    print("\n表数据示例:")
    cursor.execute("SELECT * FROM property_user LIMIT 5")
    users = cursor.fetchall()
    
    if users:
        print("\n查询到的用户数据:")
        for user in users:
            print(dict(user))
    else:
        print("\n没有找到用户数据")
    
    # 检查API中使用的查询是否能正常执行
    print("\n测试API查询:")
    try:
        cursor.execute("SELECT id, user_type, username, status FROM property_user")
        test_users = cursor.fetchall()
        print(f"成功执行查询，返回了 {len(test_users)} 条记录")
    except Exception as e:
        print(f"查询执行失败: {str(e)}")
    
    conn.close()

if __name__ == "__main__":
    check_property_user_table()
